<html><body>


<?php

$email = mysql_real_escape_string($_POST['email']);
$password = $_POST['password'];
$urlerror = 'http://localhost/isb/error.html';
//$rootpath = getcwd();
// variables

// Make a MySQL Connection
//mysql_connect("localhost", "root", "n2pl") or die(mysql_error());
mysql_connect("localhost", "root", "n2pl") or die(mysql_error());
mysql_select_db("isb") or die(mysql_error());

//get userId
$result1 = mysql_query("SELECT * FROM employee
 WHERE EmailId = '$email'") or die(mysql_error());
$row1 = mysql_fetch_array( $result1 );
$userid = $row1['UserId'];

// check password based on userId
$result2 = mysql_query("SELECT * FROM UserRoleId
 WHERE UserId= '$userid'") or die(mysql_error());  
// get the first (and hopefully only) entry from the result
$row2 = mysql_fetch_array( $result2 );

if($row2['LoginPassword'] == $password ){
//--**************************************** Change login status to 1
$status = 1;


/*
// Get a specific result from the "example" table
$result = mysql_query("SELECT * FROM UserRoleId
 WHERE email= '$email'") or die(mysql_error());  
// get the first (and hopefully only) entry from the result
$row = mysql_fetch_array( $result );

// Print out the contents of each row into a table 
if($row['LoginPassword'] == $password){
//--**************************************** Change login status to 1
$status = 1;
*/

$lastlogindate = date("Y/m/d");
$lastdatemodified = date("Y/m/d");



// update the LastLoginDate in UserRoleId table in database 

mysql_query("UPDATE UserRoleId SET LastLoginDate = '$lastlogindate'
 WHERE UserId = '$userid'") 
or die(mysql_error());


// update the LastDateModified in employee table in database
mysql_query("UPDATE employee SET LastDateModified = '$lastdatemodified'
 WHERE EmailId = '$email'") 
or die(mysql_error());

echo 'login successfully!';
//$result = mysql_query("UPDATE LoginPassword SET loginstatus='$status' WHERE email='$email'") 
//or die(mysql_error()); 
//-------------------------------------------------------------------

$urlwelcomeback = 'http://localhost/isb/employeewelcome.php';
header( "Location: $urlwelcomeback" );
}

//http://localhost/we/landing-page/accounts/mick75/profile.php
else{

header( "Location: $urlerror" );
}

?>
</body></html>
